<?php
/* @var $this CmpNewsController */
/* @var $model CmpNews */

$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
  	'图片管理'=>array($this->pre_module_url.'/album/admin'),
    '分类管理'=>array($this->pre_module_url.'/albumCat/admin'),
);
?>

<div class="addtype_tab bd_db pro_category">
	<div class="hd mem_bgx">
		<ul class="c_f">
			<li class="a">分类名称</li>
			<li class="b"> &nbsp;</li>
			<li class="c">移动</li>
			<li class="d">查看分类下的宝贝</li>
			<li class="e">删除</li>
		</ul>
	</div>
	<div class="bd addtype_tab" id="addClass">
        <?php $form = $this->beginWidget ( 'CActiveForm', array (
					'id' => 'cmpCat-form',
					'enableAjaxValidation' => false,
					'action' => 'save',
					'htmlOptions' => array (
							'enctype' => 'multipart/form-data' 
					) 
			) );
			?>
	        <div class="add_type">
				<span class="c_666 f_r d_n">注意：添加分类图片的规格为：186*27px</span>
				<?php echo CHtml::linkbtn('添加新分类',"javascript:",array('onclick'=>'createCat(0)'))?>
			</div>

            <?php $this->widget ( 'zii.widgets.CListView', array (
					'dataProvider' => CmpCat::model ()->getCatlist ( 0, 3 ),
					'itemView' => '_view',
					'itemsCssClass' => '',
					'template' => '{items}',
            		'itemsTagName'=>'ul',
            		'tagName'=>'div',
            		'htmlOptions'=>array('class'=>'type_list'),
            		'itemsOptions'=>array('class'=>'main_class'),
			) );
			?>

			<div class="add_type">
				<?php echo CHtml::linkbtn('添加新分类',"javascript:",array('onclick'=>'createCat(0)'))?>
				<?php echo CHtml::submitButton(Yii::t('adm','Save'),array('class'=>'mem_btn mem_btn13'))?>
			</div>
        <?php $this->endWidget(); ?>
	</div>
</div>


<!-- 上传 -->
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js'></script>
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js'></script>
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js'></script>

<!-- 添加分类 -->
<link href="/js/artdialog/skins/default.css" rel="stylesheet" />
<script src="/js/artdialog/artDialog.min.js"></script>

<!--宝贝分类管理 end-->
<script type="text/javascript">
$(function(){
	$('.type_list').TypeList();
	$('.type_list').Prolist();
	$('.category_tab').ClassifyTab();
});

$('.ico_fold').bind('click',function(){
	$(this).parent().parent().parent().addClass('open');
})

//移动
$(function (){
	updataParentclass();
});

$(function () {
	//父级下移
	$('.p_down').live('click',function(){
		var parent = $(this).parent().parent().parent().parent();
		$(this).parent().parent().parent().removeClass('cur');
		parent.next('li').after(parent);
		updataParentclass();
		
	});
	//父级上移
	$('.p_up').live('click',function(){
		var parent = $(this).parent().parent().parent().parent();
		$(this).parent().parent().parent().removeClass('cur');
		parent.prev('li').before(parent);
		updataParentclass();
	});	
	//子级下移
	$('.c_down').live('click',function(){
		var parent = $(this).parent().parent().parent().parent();
		$(this).parent().parent().parent().removeClass('cur');
		parent.next('li').after(parent);
		updataChildclass(parent);
		
	});
	//子级上移
	$('.c_up').live('click',function(){
		var parent = $(this).parent().parent().parent().parent();
		$(this).parent().parent().parent().removeClass('cur');
		parent.prev('li').before(parent);
		updataChildclass(parent);
	});			
})

//改变第一级分类的样式
function updataParentclass(){
    $(".main_type").find('.p_up').attr({class:'mem_ico ord_3 up p_up'});
	$(".main_type").find('.p_down').attr({class:'mem_ico ord_4 down p_down'});				
	$(".main_type").last().find('.p_up').attr({class:'mem_ico ord_3 up p_up'});
	$(".main_type").last().find('.p_down').attr({class:'mem_ico ord_2 down p_down'});
	$(".main_type").first().find('.p_down').attr({class:'mem_ico ord_4 down p_down'});
	$(".main_type").first().find('.p_up').attr({class:'mem_ico ord_1 up p_up'});
}	
//改变子分类样式
function updataChildclass(parent){
    parent.parent().children().find('.c_up').attr({class:'mem_ico ord_7 up c_up'});
	parent.parent().children().find('.c_down').attr({class:'mem_ico ord_8 down c_down'});				
    parent.parent().children().first().find('.c_up').attr({class:'mem_ico ord_5 up c_up'});
    parent.parent().children().first().find('.c_down').attr({class:'mem_ico ord_8 down c_down'});
    parent.parent().children().last().find('.c_up').attr({class:'mem_ico ord_7 up c_up'});
    parent.parent().children().last().find('.c_down').attr({class:'mem_ico ord_6 down c_down'});
}	

//上传图片
function uploadimg (id) {
	   $('#uploadimg'+id).fileupload({         	
	        dataType: 'json',       
	        url: '/Attachment/GetAjax',        
	        success: function (json) {
	               if(json.upfile.errors=='1'){
	               		alert(json.upfile.msg);
	               }else if(json.upfile.errors=='2'){
	               		alert(json.upfile.msg);
	               }else{
		                 //修改按钮图标
		            	 $('#data_zpc_pic'+id).parent().find('img').attr('src','/images/class_okimg.gif');
						 //修改按钮文本
		            	 $('#data_zpc_pic'+id).parent().find('em').text('修改图片');
						 //修改隐藏域值
	               		 $('#data_zpc_pic'+id).attr('value',json.upfile.file);
	               } 	
	        }
	    });
};		

//添加分类
function createCat(prentid){
	art.dialog({
		title: '添加分类',
		content: '分类名称:<input type="text" id="zpc_catname" name="name"/>',
		height: '150px',
		width: '320px',
		okValue: '确定',
		cancelValue: '取消',
		cancel: function () {},
		ok:function () {
			var zpc_catname = $('#zpc_catname').val();
			if(zpc_catname.length>0){
				window.location.href = "<?php echo $this->pre_module_url?>/album/createAlbum?prentid="+prentid+"&zpc_catname="+zpc_catname;
			}else{
			    alert("分类名不能为空");
			}
		}
	});
}
 </script>